import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const jsencrypt = {}

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCJ50bCPSXv05D24J4X4iappqUE9cOuAUOmeVR6PC0AA635CTGFoIKwWMHszfhEwYhYVf92Z44+cSuqxBIt7dtMd/wB0uD6PIgWSRdIjfGSi+AY8Ga++7lgyzQWzhdxaRDocoFjYZ3uE0Jvjbm0TcyYhhhe0MFQI729UeUNho8/pQIDAQAB'

const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAInnRsI9Je/TkPbgnhfiJqmmpQT1w64BQ6Z5VHo8LQADrfkJMYWggrBYwezN+ETBiFhV/3Znjj5xK6rEEi3t20x3/AHS4Po8iBZJF0iN8ZKL4BjwZr77uWDLNBbOF3FpEOhygWNhne4TQm+NubRNzJiGGF7QwVAjvb1R5Q2Gjz+lAgMBAAECgYBCbPTYezva2b3qLSf5uSWGco7qZLdtCY7ckXTvrCzA5QTYAGWqSDarWxWOS2hbNh3G7yWukxMhYMH375oSJZCL/FXZqDj/BgVOsW8QRTw059o2RXq0KYzjphtLU7UZK90U6q1+1zoYYqMVZSWuR2jWhW+tZfG06L4/lk/GIoZxwQJBAOWd0Yac5TFMSw/AnF94AxARb6rqh/DRiO2hOoedXViDZ0EnQOP8Vu7iEAzMMa5rjuVnESDU7KVnvwtcdLlVrtMCQQCZv7abQ1/rJli6dateQIRr/BbqAJz+LnNp2AGm4P8qtj2HfNS7MNbgbF/0tMfu/SVHX4l1Bf3QLwAOGMeflHynAkB/gdD9aJjZdF1mZPYxCarhvFz/U3ej4iegldyzvE4+vdGT26FsOQ9pXj29bZLVIcNbXo2jZrn27BKp03C6DnujAkBG/VIfVniPZuFJFtPNbRS3l2otGaNjaac4k9gPaYvn+MVoLac7100fympz3pUCMDhqQB6DvgR3f3wTBjYF5NW5AkEArIctrURg9HxlnHanWc6AzgTtRUdF5mToa4RPzlGKfHZ2wO/afxpB4g1RO1Tebf5FuziyGzpkZxoqLdmVHmD1kg=='

// 加密
jsencrypt.encrypt = function (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
jsencrypt.decrypt = function (txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}

export default jsencrypt
